#include <bits/stdc++.h>
using namespace std;

bool isLeap(int year) {
    if (year % 4 != 0) return false;
    if (year % 100 != 0) return true;
    return (year % 400 == 0);
}

int monthDays[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

void nextDay(int &y, int &m, int &d) {
    d++;
    int daysInMonth = monthDays[m];
    if (m == 2 && isLeap(y)) {
        daysInMonth = 29;
    }
    if (d > daysInMonth) {
        d = 1;
        m++;
        if (m > 12) {
            m = 1;
            y++;
        }
    }
}

int main() {
    string startDate;
    cin >> startDate;
    int y = stoi(startDate.substr(0,  4));
    int m = stoi(startDate.substr(5,  2));
    int d = stoi(startDate.substr(8,  2));
    
    vector<vector<bool>> classDays(23, vector<bool>(8, false)); // weeks 1-22, days 1-7
    
    cin.ignore(); 
    string line;
    while (getline(cin, line)) {
        if (line.empty())  break;
        stringstream ss(line);
        string weekRange;
        int weekday;
        string timeRange, type, courseId;
        ss >> weekRange >> weekday >> timeRange >> type >> courseId;
        
        int fromWeek, toWeek;
        size_t dashPos = weekRange.find('-'); 
        if (dashPos != string::npos) {
            fromWeek = stoi(weekRange.substr(0,  dashPos));
            toWeek = stoi(weekRange.substr(dashPos  + 1));
        } else {
            fromWeek = stoi(weekRange);
            toWeek = fromWeek;
        }
        
        for (int week = fromWeek; week <= toWeek; ++week) {
            bool add = false;
            if (type == "All") {
                add = true;
            } else if (type == "Odd" && week % 2 == 1) {
                add = true;
            } else if (type == "Even" && week % 2 == 0) {
                add = true;
            }
            if (add && week <= 22) {
                classDays[week][weekday] = true;
            }
        }
    }
    
    map<string, int> dateMap;
    vector<string> dates;
    int currentY = y, currentM = m, currentD = d;
    
    for (int week = 1; week <= 22; ++week) {
        for (int day = 1; day <= 7; ++day) {
            if (week == 1 && day == 1) {
                // first day is the starting Monday (week 1, day 1)
            } else {
                nextDay(currentY, currentM, currentD);
            }
            if (classDays[week][day]) {
                char dateStr[11];
                sprintf(dateStr, "%04d-%02d-%02d", currentY, currentM, currentD);
                dates.push_back(dateStr); 
            }
        }
    }
    
    sort(dates.begin(),  dates.end()); 
    cout << dates.size()  << endl;
    for (const string &date : dates) {
        cout << date << endl;
    }
    
    return 0;
}